package com.tchepannou.limbe.web.servlet;

import com.tchepannou.util.IOUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * Handle request for robot.txt
 */
public class FaviconServlet
    extends HttpServlet
{
    private static final String FILE = "/favicon.ico";

    //-- HttpServlet overrides
    @Override
    protected void service (HttpServletRequest req, HttpServletResponse resp)
        throws ServletException,
               IOException
    {
        String file = getServletContext().getRealPath(FILE);
        InputStream in = new FileInputStream(file);
        try
        {
            OutputStream out = resp.getOutputStream();
            IOUtil.copy(in, out);
        }
        finally
        {
            in.close();
        }
    }
}
